﻿using System;

namespace Fee.Orders
{
    public class DelegateOrderDetail
    {
        public int Id { get; set; }
        public ConstructionType ConstructionType { get; set; }

        public FrameworkContract Contract { get; set; }
        public ContractType ContractType { get; set; }

        public int? SourceConstructionDetailId { get; set; }

        public ConstructionOperator Operator { get; set; }

        public Project Project { get; set; }


        public ConstructionDetail FillTo(ConstructionDetail detail)
        {
            if (Contract == null) throw new ArgumentException("框架合同必须指定");

            if (Project == null) throw new ArgumentException("项目必须指定");
            detail.ConstructionType = ConstructionType;
            detail.Contract = Contract;
            detail.ContractType = ContractType;
            detail.Project = Project;
            return detail;
        }

        public bool UpdateBy(DelegateOrderDetail item)
        {
            var hasChanged = false;
            if (Project == null || Project.Id != item.Project.Id)
            {
                hasChanged = true;
                Project = item.Project;
            }

            if (Contract == null || Contract.Id != item.Contract.Id)
            {
                Contract = item.Contract;
                hasChanged = true;
            }

            return hasChanged;
        }
    }
}